<?php

namespace Project\ScrumBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class ProjetType extends AbstractType {

    public function buildForm(FormBuilderInterface $builder, array $options) {
        $builder
                ->add('nom', 'text')
                ->add('date_debut', 'date')
                ->add('date_fin', 'date')
                ->add('ref_client', 'entity', array(
                    'class' => 'Project\ScrumBundle\Entity\Utilisateur',
                    'property' => 'email',
                    'label' => 'Client : ',
                    'query_builder' => function (\Doctrine\ORM\EntityRepository $er) {
                        return $er->createQueryBuilder('utilisateur')
                                ->where('utilisateur.refRole = :param')
                                ->setParameter('param',4); // 4 = ROLE_CLIENT
                    },
                ));
        ;
    }

    public function setDefaultOptions(OptionsResolverInterface $resolver) {
        $resolver->setDefaults(array(
            'data_class' => 'Project\ScrumBundle\Entity\Projet'
        ));
    }

    public function getName() {
        return 'project_scrumbundle_projettype';
    }

}
